package server;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class Get {
	public static String Whois(String domain)
	{
		String content = "";
		String result="";
		try {
			URL url = new URL("http://www.check-whois.com/query.php");
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			connection.setDoOutput(true);
			connection.setRequestMethod("POST");
			connection.setRequestProperty("Content-Type",
					"application/x-www-form-urlencoded");
			OutputStreamWriter writer = new OutputStreamWriter(
					connection.getOutputStream());
			writer.write("query="+domain);
			writer.write("&button=Search");
			writer.close();

			if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
				BufferedReader reader = new BufferedReader(new InputStreamReader(
						connection.getInputStream()));
				char[] buf = new char[102102];
				int numRead = 0;
				while ((numRead = reader.read(buf)) != -1) {
					String readData = String.valueOf(buf, 0, numRead);
					content += readData;
					buf = new char[102102];
				}
				reader.close();

				Document doc = Jsoup.parse(content);
				result = doc.select("body").html();
			} 
		} catch (Exception e) {
			// TODO: handle exception
		}
		return result;
	}
}
